package com.dragonwu.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragonwu.entity.SysRole;
import com.dragonwu.mapper.SysRoleMapper;
import com.dragonwu.service.ISysRoleService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author DragonWu
 * @since 2022-10-11
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Autowired
    private SysRoleMapper sysRoleMapper;

    @Override
    public Boolean isSuperAdmin(Long userId) {
        //当前的用户code 为：ROLE_ADMIN时，该用户为超级的管理员
        //用户的id->用户的角色->该角色的Code是否ROLE_ADMIN
        String roleCode=sysRoleMapper.getUserRoleCode(userId);
        if(!StringUtils.isEmpty(roleCode) && roleCode.equals("ROLE_ADMIN")){
            return true;
        }
        return false;
    }
}
